package com.epalmpay.controller.prepurchase;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.epalmpay.commom.BaseController;
import com.epalmpay.exception.ApplicationException;
import com.epalmpay.status.Rescode;
import com.epalmpay.dto.prepurchase.ReceiceInfoInDTO;
import com.epalmpay.dto.prepurchase.ReceiceInfoListOutDTO;
import com.epalmpay.dto.system.BaseOutDTO;
import com.epalmpay.dto.system.PageDTO;
import com.epalmpay.entity.Page;
import com.epalmpay.service.prepurchase.IPrePurchaseService;
import com.epalmpay.util.Tools;

@Controller
@RequestMapping(value="/group/receiceInfo")
public class GroupReceiveInfoController  extends BaseController{
	
	@Resource  
	private IPrePurchaseService receiceInfoService;
	
	@RequestMapping(value="/saveReceiceInfo")
	@ResponseBody
	public BaseOutDTO  saveReceiceInfo(ReceiceInfoInDTO receiceInfoInDTO){
		BaseOutDTO baseOutDTO = new BaseOutDTO();
		try {
			
			 return  receiceInfoService.addReceiceInfo(receiceInfoInDTO);

		} catch (ApplicationException ae) {
			baseOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
		}
		catch (Exception e) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return baseOutDTO;
	}
	
	@RequestMapping(value="/doEditReceiceInfo")
	@ResponseBody
	public BaseOutDTO  doEditReceiceInfo(ReceiceInfoInDTO receiceInfoInDTO){
		BaseOutDTO baseOutDTO = new BaseOutDTO();
		try {
			
			 return  receiceInfoService.updateReceiceInfo(receiceInfoInDTO);

		} catch (ApplicationException ae) {
			baseOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
		}
		catch (Exception e) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return baseOutDTO;
	}
	
	@RequestMapping(value="/deleteReceiceInfo")
	@ResponseBody
	public BaseOutDTO  deleteReceiceInfo(ReceiceInfoInDTO receiceInfoInDTO){
		BaseOutDTO baseOutDTO = new BaseOutDTO();
		try {
			
			Boolean flag = receiceInfoService.deleteReceiceInfo(receiceInfoInDTO);
			if(flag){
				baseOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
				return baseOutDTO;
			}else{
				baseOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			}

		} catch (ApplicationException ae) {
			baseOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
		}
		catch (Exception e) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return baseOutDTO;
	}
	
	@RequestMapping(value="/listReceiceInfo")
	@ResponseBody
	public BaseOutDTO  listReceiceInfo(ReceiceInfoInDTO receiceInfoInDTO,PageDTO pageDTO){
		BaseOutDTO baseOutDTO = new BaseOutDTO();
		try {
			Page page=Tools.pageEmtity(pageDTO);
			ReceiceInfoListOutDTO listReceiceInfoListOutDTO= receiceInfoService.listReceiceInfo(receiceInfoInDTO,page);
			listReceiceInfoListOutDTO.setPage(page); 
			listReceiceInfoListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return listReceiceInfoListOutDTO;
		} catch (ApplicationException ae) {
			baseOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
		}
		catch (Exception e) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return baseOutDTO;
	}
	
	@RequestMapping(value="/findReceiceInfo")
	@ResponseBody
	public BaseOutDTO  findReceiceInfo(ReceiceInfoInDTO receiceInfoInDTO){
		BaseOutDTO baseOutDTO = new BaseOutDTO();
		try {
			
			return receiceInfoService.findReceiceInfo(receiceInfoInDTO); 

		} catch (ApplicationException ae) {
			baseOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
		}
		catch (Exception e) {
			baseOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
			e.printStackTrace();
		}
		return baseOutDTO;
	}
	
	
				
	
}
